unit ASetMenu;

interface

uses
  AData, AModelBrowser,

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ActnList, ComCtrls, ToolWin, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, 
  cxEdit, DB, cxDBData,
  cxControls, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid, cxTL,
  cxSplitter, cxInplaceContainer, cxTLData, cxDBTL, MemDS, DBAccess,
  MyAccess, frxClass, frxDesgn, cxMaskEdit, Menus, 
  ExtCtrls, cxContainer, cxGroupBox, StdCtrls, DBCtrls,
  cxTextEdit, cxDBEdit, cxRadioGroup, cxGraphics, cxCustomData, cxStyles,cxCheckBox,
  cxCheckGroup, cxDropDownEdit, cxCheckComboBox, ADODB;

type
  TASetMenuForm = class(TAModelBrowserFrame)
    cxDBTreeList1: TcxDBTreeList;
    cxSplitter1: TcxSplitter;
    DMenuTree: TMyDataSource;
    Panel1: TPanel;
    cxGroupBox1: TcxGroupBox;
    QMenuTree: TMyQuery;
    QMenuTreemenu_name: TStringField;
    QMenuTreemenu_desc: TStringField;
    QMenuTreeparent_name: TStringField;
    QMenuTreewindow_name: TStringField;
    QMenuTreewindowCaption: TStringField;
    QMenuTreeselect_where: TStringField;
    QMenuTreewhere_str: TStringField;
    QMenuTreeaction_visible: TIntegerField;
    menu_name: TLabel;
    menu_desc: TLabel;
    parent_name: TLabel;
    window_name: TLabel;
    windowCaption: TLabel;
    select_where: TLabel;
    where_str: TLabel;
    action_visible: TLabel;
    menu_visible: TLabel;
    cxDBedtmenu_name: TcxDBTextEdit;
    cxDBedtmenu_desc: TcxDBTextEdit;
    cxDBedtparent_name: TcxDBTextEdit;
    cxDBedtwindow_name: TcxDBTextEdit;
    cxDBedtwindowCaption: TcxDBTextEdit;
    cxDBedtselect_where: TcxDBTextEdit;
    cxDBedtwhere_str: TcxDBTextEdit;
    cxDBEdtaction_visible: TcxDBTextEdit;
    cxDBedtmenu_visible: TcxDBTextEdit;
    cxRadioGroup1: TcxRadioGroup;
    cxDBTreeList1menu_name: TcxDBTreeListColumn;
    cxDBTreeList1menu_desc: TcxDBTreeListColumn;
    cxDBTreeList1parent_name: TcxDBTreeListColumn;
    cxDBTreeList1window_name: TcxDBTreeListColumn;
    cxDBTreeList1windowCaption: TcxDBTreeListColumn;
    cxDBTreeList1select_where: TcxDBTreeListColumn;
    cxDBTreeList1where_str: TcxDBTreeListColumn;
    cxDBTreeList1action_visible: TcxDBTreeListColumn;
    cxDBTreeList1menu_visible: TcxDBTreeListColumn;
    checkBoxList: TcxCheckGroup;
    QMenuTreemenu_visible: TLargeintField;
    pnl1: TPanel;
    chkboxSelectAll: TcxCheckBox;
    procedure ActionNewExecute(Sender: TObject);
    procedure ActionSaveExecute(Sender: TObject);
    procedure QMenuTreeAfterScroll(DataSet: TDataSet);
    procedure chkboxSelectAllPropertiesChange(Sender: TObject);
  private
    { Private declarations }
  public
    constructor Create(Aowner: TComponent); override;
    destructor Destroy; override;
    procedure OpenDataSet; override;
  end;

var
  ASetMenuForm: TASetMenuForm;

implementation

{$R *.dfm}

{ TsetMenuFrm }

constructor TASetMenuForm.Create(Aowner: TComponent);
begin
  inherited Create(Aowner);
  FIsShowEdtFrm := False;
end;

destructor TASetMenuForm.Destroy;
begin

  inherited;
end;

procedure TASetMenuForm.OpenDataSet;
begin

  inherited;

end;

procedure TASetMenuForm.ActionNewExecute(Sender: TObject);
var aParent_name: string;
begin
  case cxRadioGroup1.ItemIndex of
  0: aParent_name := QMenuTreeparent_name.Value ;
  1: aParent_name := QMenuTreemenu_name.Value;
  end;
  inherited;
  cxDBedtparent_name.Enabled :=Length(aParent_name) = 1;
  QMenuTreeparent_name.Value := aParent_name;
end;

procedure TASetMenuForm.ActionSaveExecute(Sender: TObject);
var i: Integer;
    LimitValue: Integer;
begin

  if checkBoxList.States[0] = (cbsChecked) then
    QMenuTreemenu_visible.Value := 1
  else QMenuTreemenu_visible.Value := 0;

  LimitValue := 0;
  for i := 1 to checkBoxList.Properties.Items.Count -1 do
  begin
    if checkBoxList.States[i] = (cbsChecked) then
      LimitValue := LimitValue + checkBoxList.Properties.Items[i].Tag;
  end;
  if QMenuTreeaction_visible.Value <> LimitValue then
  QMenuTreeaction_visible.Value := LimitValue;

  inherited;

end;

procedure TASetMenuForm.QMenuTreeAfterScroll(DataSet: TDataSet);
var limitValue: Integer;
    i: integer;
begin
  inherited;
  limitValue :=  QMenuTreeaction_visible.Value;
  i:= QMenuTreeMenu_visible.Value;
  //0 false 1 true
  if i = 0 then checkBoxList.States[0] := cbsUnchecked else checkBoxList.States[0] := cbsChecked;

  for i := 1 to checkBoxList.Properties.Items.Count -1 do
  begin
    if checkBoxList.Properties.Items[i].Tag = (limitValue and checkBoxList.Properties.Items[i].Tag) then
      checkBoxList.States[i] := cbsChecked else checkBoxList.States[i] := cbsUnchecked;
  end;
  chkboxSelectAll.Checked := False;
end;

procedure TASetMenuForm.chkboxSelectAllPropertiesChange(Sender: TObject);
var i: integer;
begin
  for i := 0 to checkBoxList.Properties.Items.Count -1 do
     if chkboxSelectAll.Checked then
     checkBoxList.States[i] := cbsChecked else checkBoxList.States[i] := cbsUnchecked;
end;

initialization
  RegisterClass(TASetMenuForm);
finalization
  UnRegisterClass(TASetMenuForm);

end.

